package com.example.user.concurrent;

import com.example.user.bo.Person01BO;
import com.example.user.mapper.ds1.UserMapper1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CountDownLatch;

@Transactional(value = "transactionManager1")
public class InsertThread extends Thread{
    private volatile CountDownLatch countDownLatch;
    private UserMapper1 userMapper1;
    private List<Person01BO> innerList;
    public InsertThread(CountDownLatch countDownLatch,UserMapper1 userMapper1,
                        List<Person01BO> innerList){
        this.countDownLatch=countDownLatch;
        this.userMapper1=userMapper1;
        this.innerList=innerList;
    }

    @Override
    public void run() {
        System.out.println("分支线程开始工作");
        countDownLatch.countDown();
        for (Person01BO bo : innerList) {
            userMapper1.insert(bo);
            System.out.println("成功存入" + bo);
        }
    }
}
